/*
ID:luongho3
LANG:JAVA
TASK:schlnet
 */
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Stack;


public class schlnet {

	int N, nTop, nBottom, top, bottom;
	int[][] m, rm;

	public static void main(String[] args) throws Exception {
		schlnet prob = new schlnet();
		prob.read();
		prob.solve();
	}
	
	public void read() throws Exception {
		Scanner scanner = new Scanner(new File("schlnet.in"));
		N = scanner.nextInt();
		m = new int[N+1][N+1];
		rm = new int[N+1][N+1];
		for (int i=1;i<=N;++i) {
			do {
				int tmp = scanner.nextInt();
				if (tmp == 0) {
					break;
				}
				else {
					m[i][tmp] = 1;
					rm[tmp][i] = 1;
				}
			} while (true);
		}
	}
	
	public void solve() throws Exception {
		PrintStream ps = new PrintStream(new File("schlnet.out"));
		System.setOut(ps);
		top = -1;
		nTop = countTop(m, N, 1);
		bottom = -1;
		nBottom = countTop(rm, N, 2);
		if (nTop == nBottom && nTop == 1) {
			if (top == bottom) {
				System.out.println(1);
				System.out.println(0);
				ps.close();
				return;
			}
			Stack<Integer> stack = new Stack<Integer>();
			int[] visited = new int[N+1];
			visited[bottom] = 1;
			stack.push(bottom);
			while (!stack.isEmpty()) {
				int t = stack.pop();
				for (int i=1;i<=N;++i) {
					if (visited[i] != 1 && m[t][i] == 1) {
						if (i == top) {
							System.out.println(1);
							System.out.println(0);
							ps.close();
							return;
						}
						stack.push(i);
						visited[i] = 1;
					}
				}
			}
		}
		System.out.println(nTop);
		System.out.println(Math.max(nBottom, nTop));
		ps.close();
	}


	private int countTop(int[][] g, int n, int flag) {
		int[] isTop, hasTop, touched;
		isTop = new int[n+1];
		hasTop = new int[n+1];
		touched = new int[n+1];
		for (int i=1;i<=n;++i) {
			isTop[i] = 0;
			hasTop[i] = 0;
		}
		Stack<Integer> stack = new Stack<Integer>();
		for (int i=1;i<=n;++i) {
			if (hasTop[i] == 0) {
				for (int j=1;j<=n;++j) {
					touched[j] = 0;
				}
				stack.push(i);
				hasTop[i] = 1;
				touched[i] = 1;
				isTop[i] = -1;
				while (!stack.isEmpty()) {
					int top = stack.pop();
					for (int j=1;j<=n;++j) {
						if (g[top][j]==1) {
							if (touched[j] != 1) {
								isTop[j] = -1;
								hasTop[j] = 1;
								touched[j] = 1;
								stack.push(j);
							}
						}
					}
				}
				isTop[i] = 1;
			}
		}
		int count = 0;
		for (int i=1;i<=n;++i) {
			if (isTop[i] == 1) {
				count++;
				if (count == 1) {
					if (flag == 1) {
						top = i;
					}
					else if (flag == 2) {
						bottom = i;
					}
				}
			}
		}		
		return count;
	}

}
